/**
 * 获取角色对应的员工列表
 */
import React from 'react';
import { getRoleIdlist } from '@/services/organization';

const useStaff = query => {
    const { id, companyId } = query;
    const [outData, setOutData] = React.useState([]);
    const [loading, setLoading] = React.useState(true);

    const fetchData = async () => {
        setLoading(true);
        const { data = {}, code } = (await getRoleIdlist(id, companyId)) || {};

        if (code === 10000) {
            setOutData(data);
        }
        setLoading(false);
    };

    React.useEffect(() => {
        if (id && companyId) {
            fetchData();
        }
    }, [query]);

    return [loading, outData];
};

export default useStaff;
